package com.woniu.service.impl;

import com.woniu.dao.LogDao;
import com.woniu.pojo.Lesson;
import com.woniu.pojo.Log;
import com.woniu.pojo.LogExample;
import com.woniu.pojo.PageBean;
import com.woniu.service.LogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LogServiceImpl implements LogService {
    @Resource
    private LogDao logDao;

    @Override
    public void saveUser(Log systemLog) {
    }

    /**
     * 日志记录
     * @param pageBean
     * @param log
     * @return
     */
    @Override
    public List<Log> getLogList(PageBean pageBean, Log log) {
        LogExample logExample=new LogExample();
        LogExample.Criteria criteria=logExample.createCriteria();
        if (log.getUname()!=null&&!("").equals(log.getUname())){
            criteria.andUnameEqualTo(log.getUname());
        }
        Long countRow =logDao.countByExample(logExample);
        pageBean.setCountRow(countRow.intValue());
        Integer countPage = pageBean.getCountRow()%pageBean.getPageSize()==0?pageBean.getCountRow()/pageBean.getPageSize():pageBean.getCountRow()/pageBean.getPageSize()+1;
        pageBean.setCountPage(countPage);

        logExample.setOffset((long)((pageBean.getCurrentPage()-1)*pageBean.getPageSize()));
        logExample.setLimit(pageBean.getPageSize());
        logExample.setOrderByClause("ltime desc");
        List<Log> logList = logDao.selectByExample(logExample);
        return logList;
    }
}
